export default {
  state: {
    page: {/* page object */},
    news: [],
    activities: []
  },

  mutations: {
    SET_NEWS: (state, { news, page }) => {
      state.news = news
      state.page = page
    },

    SET_ACTIVITIES: (state, { activities }) => {
      state.activities = activities
    }
  },

  actions: {
    FETCH_NEWS_DATA: ({ dispatch, commit }, { params }) => {
      return Promise.all([dispatch('FETCH_NEWS', { params }), dispatch('FETCH_SIDE_ACTIVITIES')])
    },

    FETCH_NEWS: ({ dispatch, commit }, { params }) => {
      return dispatch('FETCH_ENDPOINT_DATA', {
        endpoint: 'news',
        params: params
      })
      .then(({ news, page }) => {
        commit('SET_NEWS', { news, page })
      })
    },

    FETCH_SIDE_ACTIVITIES: ({ dispatch, commit }) => {
      return dispatch('FETCH_ENDPOINT_DATA', {
        endpoint: 'activities',
        params: { per_page: 4 }
      }).then(({ activities }) => {
        commit('SET_ACTIVITIES', { activities })
      })
    }
  }
}